package com.chagee.store.operation.server.facade;

import com.chagee.base.utils.*;
import com.chagee.store.operation.api.enums.StoreWorkOrderStatusEnum;
import com.chagee.store.operation.api.request.OrderAppealRequest;
import com.chagee.store.operation.server.model.param.*;
import com.chagee.store.operation.server.model.response.SupplierTaskDetailResponse;
import com.chagee.store.operation.server.model.vo.*;
import com.chagee.store.operation.server.model.vo.mapVO.DictMapVo;
import com.chagee.store.operation.server.model.vo.mapVO.DictVo;
import com.chagee.store.operation.server.model.vo.mapVO.DictVoInt;
import com.chagee.store.operation.server.service.SupplierWorkOrderService;
import com.chagee.storeManagement.api.event.enums.ClosingTaskStatusEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName SupplierWorkOrderFacade  //类名称
 * @Description: //类描述：供应商在门店获取工单信息Service
 * @Author: Jacky-zhan	//作者
 * @CreateDate: 2024/04/25 13:49	//创建时间
 * @UpdateUser: Jacky-zhan	//作者
 * @UpdateDate: 2024/04/25 13:49	//更新时间
 * @UpdateRemark: 更新的信息
 * @Version: 1.0    //版本号
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class SupplierWorkOrderFacade {

	@Resource
	private SupplierWorkOrderService supplierWorkOrderService;

	/**
	 * 供应商在门店获取工单信息列表Service
	 *
	 * @param queryParam 查询参数
	 * @return 分页格式的列表
	 */
	public PaginationData<SupplierWorkOrderVO> list(PaginationRequest<SupplierWorkOrderQueryParam> queryParam) {
		return supplierWorkOrderService.list(queryParam);
	}

	/**
	 * 登录人为 城市骨干 角色
	 * @param queryParam
	 * @return
	 */
	public PaginationData<SupplierWorkOrderVO> queryWorkOrderList(PaginationRequest<SupplierWorkOrderQueryParam> queryParam) {
		return supplierWorkOrderService.queryWorkOrderList(queryParam);
	}

	/**
	 * 供应商在门店扫码下单
	 *
	 * @param scanCodePlaceOrderParam 下单入参
	 */
	public ScanResponse scanCodeAndPlaceOrder(ScanCodePlaceOrderParam scanCodePlaceOrderParam) {
		//先查询该门店下 待交接、待接单、待执行、执行中任一状态下的工单，如果是待交接/待接单则将状态修改为待执行，
		return supplierWorkOrderService.queryWorkOrder(scanCodePlaceOrderParam);
	}

	/**
	 * 获取获取 子公司/门店 （主账户查询供应商的子公司/门店，子账户查询自己对应的子公司/门店）
	 *
	 * @param getCompanyStoreParam 获取 子公司/门店 入参
	 * @return list
	 */
	public List<CompanyVO> getCompanyList(GetCompanyStoreParam getCompanyStoreParam) {
		return supplierWorkOrderService.getCompanyList(getCompanyStoreParam);
	}

	/**
	 * 获取获取 子公司-门店 （主账户查询供应商的子公司-门店，子账户查询自己对应的子公司-门店）
	 *
	 * @param getCompanyStoreParamPaginationRequest 获取 子公司-门店 入参
	 * @return page对象
	 */
	public PaginationData<CompanyStorePageVO> getCompanyStoreList(PaginationRequest<GetCompanyStoreParam> getCompanyStoreParamPaginationRequest) {
		return supplierWorkOrderService.getCompanyStoreList(getCompanyStoreParamPaginationRequest);
	}

	/**
	 * 通过门店编码查询子公司id/name
	 *
	 * @param reQueryCompanyParam 门店编码
	 * @return CompanyStoreVO
	 */
	public CompanyStoreVO getCompanyByStore(ReQueryCompanyParam reQueryCompanyParam) {
		return supplierWorkOrderService.reQueryCompanyParam(reQueryCompanyParam);
	}

	/**
	 * 点击工单列表查询 工单信息+任务信息
	 *
	 * @param supplierWorkOrderTaskParam 工单id对象
	 * @return 工单信息+任务信息
	 */
	public SupplierWorkOrderTaskVO queryData(SupplierWorkOrderTaskParam supplierWorkOrderTaskParam) {
		return supplierWorkOrderService.queryData(supplierWorkOrderTaskParam);
	}

	/**
	 * 门店获取接单人完成所有打烊任务
	 *
	 * @param supplierDealWorkOrderParam 工单编号
	 * @return 工单信息
	 */
	public SupplierWorkOrderTaskVO dealWorkOrder(SupplierDealWorkOrderParam supplierDealWorkOrderParam) {
		return supplierWorkOrderService.dealWorkOrder(supplierDealWorkOrderParam);
	}

	/**
	 * 供应商确认预打烊交接信息
	 *
	 * @param supplierDeviceConfirmHandoverParam 工单编号+确认预打烊交接信息
	 * @return 工单信息
	 */
	public Boolean confirmHandoverData(SupplierDeviceConfirmHandoverParam supplierDeviceConfirmHandoverParam) {
		return supplierWorkOrderService.confirmHandoverData(supplierDeviceConfirmHandoverParam);
	}

	/**
	 * 供应商对工单任务验收结果不合格的提起申诉
	 *
	 * @param submitAppealRequest 提交申诉参数
	 * @return boolean
	 */
	public Boolean submitAppeal(SubmitAppealRequest submitAppealRequest) {
		return supplierWorkOrderService.submitAppeal(submitAppealRequest);
	}

	public DictMapVo dictionary() {
		DictMapVo dictMapVo = new DictMapVo();

		//三方打烊任务状态
		List<DictVoInt> closingTaskStatus = Arrays.stream(ClosingTaskStatusEnum.values()).map(ClosingTaskStatusEnum -> {
			DictVoInt vo = new DictVoInt();
			vo.setValue(ClosingTaskStatusEnum.getType());
			vo.setLabel(ClosingTaskStatusEnum.getDesc());
			return vo;
		}).collect(Collectors.toList());
		dictMapVo.setClosingTaskStatusDict(closingTaskStatus);
		//工单状态
		List<DictVo> workOrderStatus = Arrays.stream(StoreWorkOrderStatusEnum.values()).map(storeWorkOrderStatusEnum -> {
			DictVo vo = new DictVo();
			vo.setValue(String.valueOf(storeWorkOrderStatusEnum.getType()));
			vo.setLabel(storeWorkOrderStatusEnum.getDesc());
			return vo;
		}).collect(Collectors.toList());
		DictVo vo = new DictVo();
		vo.setValue("100");
		vo.setLabel("全部");
		workOrderStatus.add(0, vo);
		dictMapVo.setWorkOrderStatus(workOrderStatus);

		return dictMapVo;
	}

	/**
	 * 供应商对工单的单独任务进行处理/修改
	 *
	 * @param supplierDealTaskRequest 任务处理/修改入参对象
	 * @return TaskExecutionDetailResponse
	 */
	public TaskExecutionDetailResponse dealTask(SupplierDealTaskRequest supplierDealTaskRequest) {
		return supplierWorkOrderService.dealTask(supplierDealTaskRequest);
	}

	/**
	 * 获取任务详细信息
	 *
	 * @param supplierTaskExecutionParam 任务id
	 * @return 任务信息
	 */
	public SupplierTaskDetailResponse getTaskInfo(SupplierTaskExecutionParam supplierTaskExecutionParam) {
		SupplierTaskDetailResponse supplierTaskDetailResponse = supplierWorkOrderService.getTaskInfo(supplierTaskExecutionParam);
		return supplierTaskDetailResponse;
	}

	public Boolean orderAppeal(OrderAppealRequest request) {
		return supplierWorkOrderService.orderAppeal(request);
	}
}
